package com.example.lxj.qa.controller;

import java.util.List;
import java.util.Optional;

import com.example.lxj.base.annoation.Permission;
import com.example.lxj.base.controller.BaseController;
import com.example.lxj.base.entity.AjaxRes;
import com.example.lxj.base.entity.PageDTO;
import com.example.lxj.base.entity.TableDataInfo;
import com.example.lxj.qa.entity.TbObjections;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.lxj.qa.service.ITbObjectionsService;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 异议Controller
 *
 * @author lxj
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/qa/objections")
public class TbObjectionsController extends BaseController {
    @Autowired
    private ITbObjectionsService tbObjectionsService;

    /**
     * 查询异议列表
     */
    @Permission(value = "qa:objections:list")
    @GetMapping("/list")
    public TableDataInfo list(TbObjections tbObjections, PageDTO pageDTO) {
        startPage(Optional.ofNullable(pageDTO.getPageNo()).orElse(1), Optional.ofNullable(pageDTO.getPageSize()).orElse(10));
        List<TbObjections> list = tbObjectionsService.selectTbObjectionsList(tbObjections);
        return getDataTable(list);
    }

    /**
     * 获取异议详细信息
     */
    @Permission(value = "qa:objections:query")
    @GetMapping(value = "/{id}")
    public AjaxRes getInfo(@PathVariable("id") Long id) {
        return success(tbObjectionsService.selectTbObjectionsById(id));
    }

    /**
     * 新增异议
     */
    @Permission(value = "qa:objections:add")
    @PostMapping
    public AjaxRes add(@RequestBody TbObjections tbObjections) {
        return toAjax(tbObjectionsService.insertTbObjections(tbObjections));
    }

    /**
     * 修改异议
     */
    @Permission(value = "qa:objections:edit")
    @PutMapping
    public AjaxRes edit(@RequestBody TbObjections tbObjections) {
        return toAjax(tbObjectionsService.updateTbObjections(tbObjections));
    }

    /**
     * 删除异议
     */
    @Permission(value = "qa:objections:remove")
    @DeleteMapping("/{ids}")
    public AjaxRes remove(@PathVariable("ids") Long[] ids) {
        return toAjax(tbObjectionsService.deleteTbObjectionsByIds(ids));
    }
}
